import React, {Component, Fragment} from 'react';
import { Redirect } from 'react-router-dom';
import {actionCreators} from "./store";
import {connect} from "react-redux";
import ParticlesBg from "../common/particles/index";
import Header from "../common/header/index";
import MenuL from "../common/menu/index";
import CRouter from "./routers/index";

class Pages extends Component {
    render() {
        const {loginStatusPages } = this.props;
        if (loginStatusPages) {
            return (
                <Fragment>
                    <div className='main'>
                        <div className='main-box'>
                            <MenuL
                                loginStatusPages={loginStatusPages}
                            />
                            <div className='main-R'>
                                <Header/>
                                <CRouter/>
                            </div>
                        </div>
                        <ParticlesBg/>
                    </div>
                </Fragment>
            )
        }else {
            return <Redirect to='/'/>
        }
    }
    
    // 挂载后执行
    componentDidMount() {
        this.props.changeMenuData();
    }
}
const mapState = (state) => ({
    loginStatusPages: state.getIn(['login', 'login']),
    dhOut: state.getIn(['pages', 'show']),
});
const mapDispatch = (dispatch) => ({
    changeMenuData() {
        const action = actionCreators.getMenu();
        dispatch(action);
    },
});
export default connect(mapState, mapDispatch)(Pages);
